package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.specialcookboy.config.SpecialCookBoyConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.specialcookboy.SpecialCookBoyMgr;

import java.util.ArrayList;

public class SpecialCookBoyRecycleStrategy extends AbstractItemRecycleStrategy{


    @Override
    public void markNeedRecycleItem() {
        SpecialCookBoyConfig config = SpecialCookBoyMgr.getConfig();
        if (config == null){
            return;
        }
        ActivityInfo activityInfo = SpecialCookBoyMgr.getActivityInfo();
        if (activityInfo == null){
            return;
        }
        long recycleTime = activityInfo.getEndShowTime() * 1000L + gapTime;
        ActivityItemRecycleMgr.addRecycleItemData(config.getTipItemId(), activityType, 1, recycleTime, new ArrayList<>());
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SpecialCookBoy.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1){
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = SpecialCookBoyMgr.getActivityInfo();
        return ActivityMgr.activityInTime(activityInfo);
    }
}
